package cn.zcx;

import java.util.concurrent.TimeUnit;

/**
 * description:
 * author:zcx
 * lenovo
 * 时间：2022.02.07.16.19
 */
public class T23 {
    public static volatile boolean exit = false;  //退出标志
    public static void main(String[] args) {
        var t=new Thread(()->{
            String tn=Thread.currentThread().getName();
            System.out.printf("%s启动%n",tn);
            while (true) {
                try {
                    TimeUnit.SECONDS.sleep(1);
                    System.out.println("worker.....");
                } catch (InterruptedException e) {
                    e.printStackTrace();

                }
            }
        },"T1");
        t.start();
        try {
            Thread.sleep(1000 * 5);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        exit = true;//5秒后更改退出标志的值,没有这段代码，线程就一直不能停止
    }

}
